package com.front.peikuahaitao.view.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.front.peikuahaitao.R;
import com.front.peikuahaitao.base.BaseFragment;
import com.front.peikuahaitao.bean.User;
import com.front.peikuahaitao.presenter.PersonalPresenter;
import com.front.peikuahaitao.view.activity.LoginActivity;
import com.front.peikuahaitao.view.impl.IPersonalView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;
import cn.bmob.v3.listener.QueryListener;

/**
 * 个人中心
 */
public class PersonalFragment extends BaseFragment<IPersonalView, PersonalPresenter> {
    private static PersonalFragment instance = null;
    @BindView(R.id.image_user)
    ImageView imageUser;
    @BindView(R.id.text_login)
    TextView textLogin;
    @BindView(R.id.text_userName)
    TextView textUserName;
    @BindView(R.id.text_register)
    TextView textRegister;
    @BindView(R.id.relative_title)
    RelativeLayout relativeTitle;
    @BindView(R.id.text_my)
    TextView textMy;
    @BindView(R.id.text_all)
    TextView textAll;
    @BindView(R.id.image_pay)
    ImageView imagePay;
    @BindView(R.id.linear_order)
    LinearLayout linearOrder;
    @BindView(R.id.text_personal)
    TextView textPersonal;
    @BindView(R.id.linear_personal)
    LinearLayout linearPersonal;
    @BindView(R.id.text_customer)
    TextView textCustomer;
    @BindView(R.id.linear_customer)
    LinearLayout linearCustomer;
    @BindView(R.id.relative_help)
    RelativeLayout relativeHelp;

    public static PersonalFragment newInstance() {
        if (instance == null) {
            instance = new PersonalFragment();
        }

        return instance;
    }

    public PersonalFragment() {
        // Required empty public constructor
    }


    @Override
    public PersonalPresenter initPresenter() {
        return new PersonalPresenter();
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_personal;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {

    }


    @OnClick({R.id.image_user, R.id.text_login, R.id.text_register})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.image_user:
                break;
            case R.id.text_login:
                Intent intent = new Intent(getContext(), LoginActivity.class);
                startActivity(intent);
                break;
            case R.id.text_register:
                break;
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        BmobQuery<User> bmobQuery = new BmobQuery<User>();
        bmobQuery.addWhereEqualTo("userName", 13);
        bmobQuery.setLimit(3);
        bmobQuery.findObjects(new FindListener<User>() {
            @Override
            public void done(List<User> list, BmobException e) {
                if (list.size() != 0) {
                    textUserName.setText(list.get(0).getPassWord());
                    textLogin.setVisibility(View.GONE);
                    textRegister.setVisibility(View.GONE);
                }
            }
        });
    }
}

